//
//  NotLoginController.swift
//  maopu
//
//  Created by xiongsh on 2017/5/2.
//  Copyright © 2017年 maopu. All rights reserved.
//

import UIKit

class NotLoginController: BaseViewController, UITableViewDelegate, UITableViewDataSource, NotLoginHeaderViewDelegate {
    fileprivate var table: UITableView!
    fileprivate var arrayData: NSArray!
    fileprivate var headerView: NotLoginHeaderView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initData()
        self.initView()
        
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(true, animated: true)
    }
    func initData() {
        self.arrayData = [[["title":"我的消息","image":"mynews"]],[["title":"我发表的帖子","image":"wofabiaodetiezi"],["title":"我的回复","image":"wodehuifu"],["title":"我的收藏","image":"wodeshoucang"],["title":"我顶过的帖子","image":"wodingguode"],["title":"浏览记录","image":"liulanjilu"]],[["title":"系统设置","image":"xitongshezhi"],["title":"意见反馈","image":"yijianfankui"],["title":"分享猫扑给好友","image":"fenxiangpengyou"]]]
    }
    func initView() {
//        self.view.backgroundColor = UIColor.white
        
        self.table = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: AppWidth, height: AppHeight), style: .plain)
        self.table.delegate = self
        self.table.dataSource = self
        self.table.register(UITableViewCell.self, forCellReuseIdentifier: "NotLoginController")
        self.table.rowHeight = 55.0
        self.table.showsVerticalScrollIndicator = false
        self.view.addSubview(self.table)
        
        self.headerView = NotLoginHeaderView.init(frame: CGRect.init(x: 0, y: 0, width: AppWidth, height: 195.0 + 60))
        self.headerView.delegate = self
        self.table.tableHeaderView = self.headerView
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return self.arrayData.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (self.arrayData[section] as! NSArray).count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "NotLoginController", for: indexPath)
        let valuc: NSDictionary = (self.arrayData[indexPath.section] as! NSArray)[indexPath.row] as! NSDictionary
        cell.textLabel?.text = valuc.object(forKey: "title") as! String?
        cell.accessoryType = .disclosureIndicator
        cell.imageView?.image = UIImage.init(named: (valuc.object(forKey: "image") as! String?)!)
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
//        let vc = PreLoginContrillor()
//        self.navigationController?.pushViewController(vc, animated: true)
        if indexPath.section == 2 {
            switch indexPath.row {
            case 0:
                let vc = SettingsController()
                self.navigationController?.pushViewController(vc, animated: true)
                break
                
            case 1:
                let vc = FeedbackController()
                self.navigationController?.pushViewController(vc, animated: true)
                break
                
            case 2:
                
                break
                
            default:
                
                break
            }
        }
        else {
            let vc = PreLoginContrillor()
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 5.0
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
    func  notLoginBtnSignClick() {
        
    }
}
